Repository navigation
refactor: move main.py's code into an action package - #355
Conversation
main.py held all 3,037 lines of the action. Its code now lives in
action/, one module per part of the work, and main.py keeps only
main() and the two helpers it calls:
- escape: escaping text for the step log and workflow commands
- inputs: the inputs, read from the environment action.yml sets
- model: ScopeResult and the run's overall status
- context: the event, the pull request and its commits
- base_config: config-source: base
- cli: running commit-check and turning its JSON into scopes
- render: the step log and the Markdown report
- publish: job summary, result output, PR comment, AI label
Nothing changed in what the action does. Every function, class and
constant is moved as is; a name used from another module is now
written as module.name, so a test patches it in one place. action.yml
still runs main.py, and the action's output is byte for byte the same.
The tests change only where they reach the code: main.X becomes
module.X and patch("main.X") becomes patch("action.module.X").
Coverage now measures main.py and action/, and stays at 100%.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 8 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #355 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 1 9 +8
Lines 1257 1281 +24
=========================================
+ Hits 1257 1281 +24
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Second of two steps that split the action's code by area (the first was #354, tests only). This PR moves main.py's code into an
action/package. Nothing changes in what the action does.Before vs after
main.py: 3,037 lines, all the codemain.py: 69 lines,main()and the two helpers it calls; action.yml still runs itaction/: 8 modules, the largest 1,212 linesaction/escape.py_log_safe,_annotation_escape)action/inputs.pyaction/model.pyScopeResult,Commit, the run's overall status and exit codeaction/context.pyaction/base_config.pyconfig-source: baseaction/cli.pyaction/render.pyaction/publish.pyresultoutput, PR comment, AI labelDependencies only point down the list: nothing imports a module below it, so there are no import cycles. The report and the step log stay in one module because the step log uses about 20 of the report's helpers.
Nothing in the code changed
module.name. With that prefix removed, every definition parses to the same AST as before.module.namerather thanfrom module import name: each name is looked up in the one module that defines it, so a test that patches it patches it everywhere.resultoutput, exit code) is byte for byte the same as main's in 6 local runs: message + branch, dry run, an invalid boolean input, author + files, message-ai-attribution, and an invalid config-source.v2tag are untouched.python main.pyputs the action's own directory onsys.path, soaction/imports from there. The caller's checkout is not on the path, so nothing in it can shadow the package.Tests
main.Xbecomesmodule.X, andpatch("main.X")becomespatch("action.module.X").patch("main.subprocess.run")becomespatch("subprocess.run"), which patches the same object.TestReconfigureIoandTestLogErrorAndExitmove to tests/main_test.py, next to the code they test.mainandaction, and both are at 100%.